package com.dq.Controller;

import com.dq.Pojo.Result;
import com.dq.Pojo.Subwork;
import com.dq.Service.SubworkService;
import com.github.pagehelper.PageInfo;
import org.apache.poi.ss.formula.functions.Intercept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/subwork")
public class SubworkController {
    @Autowired
    private SubworkService subworkService;
    @PostMapping("/add")
    public Result add(@RequestBody Subwork subwork){
        if (subwork.getSubworkid()==null){
            subworkService.add(subwork);
        }else{
            subworkService.update(subwork);
        }

        return Result.success();
    }


    @GetMapping("/findByid")
    public Result findByid(@RequestParam Integer homeworkId,@RequestParam Integer stuId){

        Subwork subwork=subworkService.findByid(homeworkId,stuId);
        System.out.println(subwork);
        return Result.success(subwork);
    }

    @GetMapping("/review")
    public Result review(@RequestParam Integer homeworkId,@RequestParam Integer stuId){

        Subwork subwork=subworkService.review(homeworkId,stuId);
        System.out.println(subwork);
        return Result.success(subwork);
    }

    @GetMapping("/ByworkId")
    public Result find(@RequestParam Integer id){
        List<Subwork> subworkList=subworkService.find(id);
        return  Result.success(subworkList);
    }


    @GetMapping("/getworkgrade")
    public Result getworkgrade(@RequestParam Integer pageNum,
                               @RequestParam Integer pageSize,
                               @RequestParam Integer stuId,
                               @RequestParam Integer courseId,
                               @RequestParam String type){
        PageInfo<Subwork> subworkPageInfo=subworkService.getworkgrade(pageNum,pageSize,stuId,courseId,type);
        return Result.success(subworkPageInfo);
    }

    @GetMapping("/getgradeAll")
    public Result getgradeAll(@RequestParam Integer pageNum,
                               @RequestParam Integer pageSize,
                               @RequestParam Integer courseId,
                               @RequestParam Integer classId,
                               @RequestParam String stuId,
                               @RequestParam String type){
        PageInfo<Subwork> subworkPageInfo=subworkService.getgradeAll(pageNum,pageSize,courseId,classId,stuId,type);
        return Result.success(subworkPageInfo);
    }

}
